/**
 * @author yuyangyang
 * @time 2015/2/27
 */

define(function (require) {
    var angular = require('angular');
    require('angularRoute');
    require('./controllers');
    require('./services');
    require('./directives');

    angular.element(document).ready(function () {
        angular.bootstrap(document, ['myModule']);
    });

    angular.module('myModule', ['ngRoute', 'controllers', 'directives'])

        .run(function ($rootScope, ownerService) {
            ownerService.getMessage(function (user) {
                if (user) {
                    $rootScope.isLogin = true;
                    $rootScope.owner = user;
                } else {
                    $rootScope.isLogin = false;
                }
            });
        })

        .config(function ($routeProvider) {

            $routeProvider

                .when('/', {
                    controller: 'SportListCtrl',
                    templateUrl: 'template/sport-list.html'
                })

                .when('/sport/new', {
                    controller: 'SportNewCtrl',
                    templateUrl: 'template/sport-new.html'
                })


                .when('/sport/:sportId', {
                    controller: 'MeetListCtrl',
                    templateUrl: 'template/meet-list.html'
                })

                .when('/meet/:sportId/new', {
                    controller: 'MeetNewCtrl',
                    templateUrl: 'template/meet-new.html'
                })

                .when('/meet/detail/:meetId', {
                    controller: 'MeetDetailCtrl',
                    templateUrl: 'template/meet-detail.html'
                })

                .when('/owner', {
                    controller: 'OwnerCtrl',
                    templateUrl: 'template/owner.html'
                })

                .when('/register', {
                    controller: 'RegisterCtrl',
                    templateUrl: 'template/register.html'
                })

                .when('/login', {
                    controller: 'LoginCtrl',
                    templateUrl: 'template/login.html'
                })

                .otherwise({
                    redirectTo: '/'
                });

        });


});














